home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Utilities / InstallerMaker™ / InstallerMaker__2.0.2_Installe / InstallerMaker™ 2.0.2 Installer / InstallerMaker Extensions / IEnd Extension / UndoFolder.IEnd.p < prev    next >
Text File  |  1994-05-03  |  7KB  |  201 lines

  1. (* ****************************************************************
  2.  
  3.         UndoFolderIEnd.p
  4.                     Translated to MPW Pascal by Jim Merritt (jam)
  5.                     based on an original C routine by Raymond Lau.
  6.                     
  7.         Copyright © 1992-93 Aladdin Systems, Inc. & Raymond Lau.
  8.         All Rights Reserved.
  9.         
  10.         In combination with the associated make file (undoFolder.make),
  11.         this source text produces an IEnd code-resource, which can
  12.         be called by a Product Installer at the end of the installation
  13.         process.  Specifications for IBeg, IMid, and IEnd code resources
  14.         are given in the documentation for the StuffIt Installer™.
  15.         
  16.         This subroutine performs the following functions:
  17.            
  18.         • Move everything within the user-specified destination folder
  19.           into the parent of that folder (i.e., one level up).
  20.         • If an item cannot be moved to the parent directory because
  21.           another item there already has the same name, then rename the
  22.           item to be moved, before actually moving it.
  23.         • Finally, delete the emptied user-specified folder.
  24.         
  25.         CHANGE HISTORY:
  26.         
  27.         VER    DATE        ENGR    DESCRIPTION
  28.         1    93.04.14    jam        Initial version, based on Lau's
  29.                                 original in C.
  30.         2    93.04.28    jam        Pascal definitions of code resources were
  31.                                 changed to be more in line with idiomatic
  32.                                 usage.  In particular, the name parameter
  33.                                 was changed to a VAR Str255 instead of a
  34.                                 value StringPtr.  Various instances where
  35.                                 name was used had to be changed to reflect
  36.                                 the new sense of the parameter.
  37.         3    93.06.16    jam        Pascal definitions of code resources were
  38.                                 changed to replace BOOLEAN parameters and
  39.                                 function return values with INTEGERs, and
  40.                                 also to replace enumeration types and SETs
  41.                                 with INTEGERs.  This was made necessary
  42.                                 when we discovered that certain Pascal
  43.                                 compilers used very eccentric enumeration
  44.                                 mechanisms, which were profoundly
  45.                                 incompatible with the original C definitions
  46.                                 at the machine-code level.  The best
  47.                                 compromise was to fall back to INTEGERs.
  48.         5    94.03.14    jam        Modified DoAfterIntalling to observe new
  49.                                 packages parameter. (NOTE: Version 4 was
  50.                                 experimental and never published.)
  51.  
  52. ****************************************************************** *)
  53. (*$Z+*) (*    Allows linker to find DoAfterInstalling without declaring it
  54.             in the interface *)
  55. UNIT IEnd;
  56.  
  57. INTERFACE (* empty -- see $Z directive, above *)
  58.  
  59. IMPLEMENTATION
  60.     (*    Putting a subroutine within a UNIT that has an empty
  61.         IMPLEMENTATION is an oft-used method for creating
  62.         a standalone code-resource in MPW Pascal.
  63.     *)
  64.  
  65. (* *********************** INCLUDES *************************** *)       
  66. USES Types,        (* for StringPtr, OSErr, noErr *)
  67.      Errors,    (* for fnfErr *)
  68.      Memory,    (* for BlockMove *)
  69.      Files,        (* for various filesystem calls and objects,
  70.                    including ioDirMask *)
  71.      OSUtils,    (* for SysBeep *)
  72.      ToolUtils,    (* for BitAnd *)
  73.      Packages;    (* for NumToString *)
  74.  
  75. CONST
  76.   IntFALSE= 0;
  77.   IntTRUE= 1;  (* (x <> IntFALSE) should be used to test for IntTRUE *)
  78.       (* Use the constant IntTRUE only when you desire to assign a TRUE
  79.        value to an INTEGER.
  80.     *)
  81.  
  82. (* ------------------------------------------------
  83. //
  84. //  DoAfterInstalling
  85. //
  86. //
  87. // ------------------------------------------------ *)
  88. FUNCTION DoAfterInstalling(    Canceled:  INTEGER;
  89.                             vRefNum: INTEGER; parID: LONGINT;
  90.                             VAR name: Str255;
  91.                             packages: INTEGER ): INTEGER;
  92.  
  93.   CONST
  94.     NameStrMaxLen= 32;
  95.  
  96.   VAR
  97.     HRec: HParamBlockRec;
  98.     DoneMovingFiles, DoneCheckingConflicts: BOOLEAN;
  99.     i, j: INTEGER;
  100.     sourcedir: LONGINT;
  101.     cmpb: CMovePBRec;
  102.     
  103.     Strg: STRING[10];
  104.     StringPtrToStrg: StringPtr; (* for type-coercion *)
  105.     newname, sourcename: STRING[NameStrMaxLen];
  106. BEGIN (* DoAfterInstalling *)
  107.     (* for type-coercion in the conflict-checking loop *)
  108.         StringPtrToStrg := @Strg;
  109.     
  110.     (* Now, the real work begins. *)
  111.     IF (Canceled = IntFALSE) THEN BEGIN
  112.         HRec.ioNamePtr := @name;
  113.         HRec.ioVRefNum := vRefNum;
  114.         HRec.ioDirID := parID;
  115.         HRec.ioFDirIndex := 0;
  116.         
  117.         IF (PBGetCatInfoSync(@HRec) <> noErr) THEN BEGIN
  118.             (* Really weird!  Nothing got unstuffed? *)
  119.             Canceled := IntTRUE;
  120.         END ELSE BEGIN
  121.             sourcedir := HRec.ioDirID;
  122.  
  123.             IF (BitAnd(HRec.ioFlAttrib, ioDirMask) <> 0)
  124.                 THEN BEGIN
  125.                     i := 1;
  126.                     DoneMovingFiles := FALSE;
  127.                     REPEAT
  128.  
  129.                         HRec.ioFDirIndex := 1;
  130.                         HRec.ioDirID := sourcedir;
  131.                         HRec.ioVRefNum := vRefNum;
  132.                         HRec.ioNamePtr := StringPtr(@sourcename);
  133.                 
  134.                         IF (PBGetCatInfoSync(@HRec) = noErr) THEN BEGIN
  135.                             j := 0;
  136.                             DoneCheckingConflicts := FALSE;
  137.                             REPEAT
  138.                                 (* See if it exists in the level above. *)
  139.                                 BlockMove(@sourcename,@newname,NameStrMaxLen);
  140.                                 (*$R-*)
  141.                                 IF (j <> 0) THEN BEGIN
  142.                                     IF (ORD(newname[0]) > (NameStrMaxLen-4))
  143.                                       THEN newname[0] := CHR(NameStrMaxLen-4);
  144.                                     NumToString(j, StringPtrToStrg^);
  145.                                 (*$R+*)
  146.                                     newname := Concat(newname,'.');
  147.                                     newname := Concat(newname, Strg);
  148.                                 END;
  149.                                 HRec.ioFDirIndex := 0;
  150.                                 HRec.ioDirID := parID;
  151.                                 HRec.ioVRefNum := vRefNum;
  152.                                 HRec.ioNamePtr := StringPtr(@newname);
  153.                     
  154.                                 IF (PBGetCatInfoSync(@HRec) = fnfErr) THEN BEGIN
  155.                                     IF (J <> 0) THEN BEGIN
  156.                                         (* hrumph -- check current level as well. *)
  157.                                         HRec.ioFDirIndex := 0;
  158.                                         HRec.ioDirID := sourcedir;
  159.                                         HRec.ioVRefNum := vRefNum;
  160.                                         HRec.ioNamePtr := StringPtr(@newname);
  161.                                         DoneCheckingConflicts := (PBGetCatInfoSync(@HRec) = fnfErr);
  162.                                     END ELSE DoneCheckingConflicts := TRUE;
  163.                                 END;
  164.                     
  165.                                 IF (NOT DoneCheckingConflicts) THEN J := J + 1;
  166.                             UNTIL DoneCheckingConflicts;
  167.                             IF (j <> 0) THEN BEGIN
  168.                                 HRec.ioDirID := sourcedir;
  169.                                 HRec.ioVRefNum := vRefNum;
  170.                                 HRec.ioNamePtr := StringPtr(@sourcename);
  171.                                 HRec.ioMisc := Ptr(@newname);
  172.                                 IF (PBHRenameSync(@HRec) <> noErr)
  173.                                     THEN BEGIN (* handle any error here *) END;
  174.                             END;
  175.                 
  176.                             cmpb.ioNamePtr := StringPtr(@newname);
  177.                             cmpb.ioVRefNum := vRefNum;
  178.                             cmpb.ioNewName := NIL;
  179.                             cmpb.ioNewDirID := parID;
  180.                             cmpb.ioDirID := sourcedir;
  181.                 
  182.                             IF (PBCatMoveSync(@cmpb) <> noErr)
  183.                                 THEN BEGIN (* handle any error here *) END;
  184.                         END (* IF NOT PBGetCatInfoSync(@HRec) *)
  185.                         ELSE DoneMovingFiles := TRUE;
  186.                     UNTIL DoneMovingFiles;
  187.             
  188.                 (* now delete the folder *)
  189.                 HRec.ioNamePtr := @name;
  190.                 HRec.ioVRefNum := vRefNum;
  191.                 HRec.ioDirID := parID;
  192.                 IF (PBHDeleteSync(@HRec) <> noErr)
  193.                     THEN BEGIN (* handle any error here *) END;
  194.             END (* IF BitAnd... *);
  195.         END (* IF THEN ELSE *);
  196.     END (* IF (NOT Canceled) *);
  197.  
  198.     DoAfterInstalling := Canceled;
  199. END (* DoAfterInstalling *);
  200.  
  201. END (* IEnd *).